package com.gxuwz.dao.impl;

import com.gxuwz.dao.UserDao;
import com.gxuwz.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl implements UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public User selectUserById(String userId) {
        String sql = "select * from sys_user where userId = ? and del_flag = 0";
        BeanPropertyRowMapper<User> userBeanPropertyRowMapper = new BeanPropertyRowMapper<User>(User.class);
        Object[] params = new Object[]{userId};
        try {
            User user = jdbcTemplate.queryForObject(sql, userBeanPropertyRowMapper, params);
            return user;
        } catch (Exception ex) {
            return null;
        }
    }

    public int updateUser(User entity) {
        String sql = "update sys_user set fullName = ?, password = ?, telephone = ? where userId = ?";
        Object[] params = new Object[]{entity.getFullName(),entity.getPassword(),entity.getTelephone(),entity.getUserId()};
        int update = jdbcTemplate.update(sql, params);
        return update;
    }
}
